using System;
using System.Collections.Generic;
using System.Text;
using Decav.Data;
using Decav.Gatsb.Application;

namespace Decav.Gatsb.Data
{
    /// <summary>
    /// Creates a new object that lazy loads a reference of a <see cref="Location"/> from the database
    /// or other data store.
    /// </summary>
    [Serializable]
    public class LocationLazyLoadReference : LazyLoadReference<Guid, Location>
    {
        /// <summary>
        /// Initializes a new <see cref="LocationLazyLoadReference"/>.
        /// </summary>
        /// <param name="locationId">The ID of the location, or <see cref="System.Guid.Empty"/>
        /// to specify no location.</param>
        public LocationLazyLoadReference(Guid locationId)
            : base(locationId)
        {
        }

        public LocationLazyLoadReference(Location location)
            : base(location.Id, location)
        {
        }

        protected override Location LoadValue()
        {
            if (Id == Guid.Empty)
                return null;

            return GatsbApplication.Current.GetLocation(Id);
        }
    }
}
